#include <iostream>
#include <vector>
using namespace std;

class Solution {
	bool can_win(int n, int status, int rest, vector<int> &dp)
	{
		if (rest <= 0) {
			return false;
		}
                
		if (dp[status] != -1) {
			return dp[status];
		}

		for (int i = 1; i <= n; i++) {
			if ((status & (1 << i)) != 0 && !can_win(n, (status ^ (1 << i)), rest - i, dp)) {
				return dp[status] = true;
			}
		}
		return dp[status] = false;
	}

    public:
	bool canIWin(int maxChoosableInteger, int desiredTotal)
	{
		if (desiredTotal == 0) {
			return true;
		}
		if (maxChoosableInteger * (maxChoosableInteger + 1) / 2 < desiredTotal) {
			return false;
		}
		vector<int> dp(1 << (maxChoosableInteger + 1), -1);
		int status = (1 << (maxChoosableInteger + 1)) - 1;
		return can_win(maxChoosableInteger, status, desiredTotal, dp);
	}
};

int main()
{
	int maxChoosableInteger = 10, desiredTotal = 40;
	cout << Solution().canIWin(maxChoosableInteger, desiredTotal) << endl;
	return 0;
}